package com.jml.非对称加密.Url转码.Controller;

import com.alibaba.fastjson.JSONObject;
import com.jml.WeiXinOAuth2.utils.HttpClientUtils;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class IndexController {

	public static void main(String[] args) throws UnsupportedEncodingException {
		String encode = URLEncoder.encode("1+1", "UTF-8");
		String decode = URLDecoder.decode(encode, "UTF-8");
		System.out.println("encode:" + encode + ",decode:" + decode);
		//----------------------------------------------------------------
		//不要对整个url进行编码，只是针对参数进行编码
		//对url前面的部分和后面的第一个？不用转码，否则会访问不到，只要对参数转码就可以了
		String url = "http://127.0.0.1:8080/indexPage?";
		// 参数转码
		String strParam = "userName=" + URLEncoder.encode("1+1", "utf-8");
		String newUrl = url + strParam;
		JSONObject result = HttpClientUtils.httpGet(newUrl);
		System.out.println("result:" + result);
	}


	@RequestMapping("/indexPage")
	public String indexPage(String userName) throws UnsupportedEncodingException {
		String encode = URLEncoder.encode("1+1", "UTF-8");
		String decode = URLDecoder.decode(encode, "UTF-8");
		System.out.println("encode:" + encode + ",decode:" + decode);

		return "";
	}

}
